package com.cly.controller;

import com.cly.base.controller.BaseController;
import com.cly.entity.Document;
import com.cly.result.JsonRequest;
import com.cly.service.IDocumentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 文章控制类
 *
 * @author by 春风能解释
 * <p>
 * 2025/3/7
 */
@RestController
@RequestMapping("/document")
@Tag(name = "文章控制类", description = "文章控制类")
public class DocumentController extends BaseController<IDocumentService, Document> {

    /**
     * 分页查询文章
     *
     * @param current  页码
     * @param size     页长
     * @param document 查询条件
     * @return JSON
     */
    @GetMapping
    @Operation(summary = "分页查询文章")
    public JsonRequest<List<Document>> lookDocument(
            @Parameter(description = "页码", required = true)
            @RequestParam Integer current,
            @Parameter(description = "页长", required = true)
            @RequestParam Integer size,
            @Parameter(description = "条件")
            Document document) {
        return baseService.lookDocument(current, size, document);
    }

    /**
     * 查询文章详情
     *
     * @param id 文章id
     * @return JSON
     */
    @GetMapping("/getOne")
    @Operation(summary = "查询文章详情")
    public JsonRequest<Document> lookOneDocument(
            @Parameter(description = "文章id", required = true)
            @RequestParam Long id) {
        return baseService.lookOneDocument(id);
    }

    /**
     * 添加文章
     *
     * @param document 文章
     * @return JSON
     */
    @PostMapping
    @Operation(summary = "添加文章")
    public JsonRequest<Integer> addOneDocument(
            @Parameter(description = "文章", required = true)
            @RequestBody Document document) {
        return baseService.addOneDocument(document);
    }

    /**
     * 修改文章
     *
     * @param document 文章
     * @return JSON
     */
    @PutMapping
    @Operation(summary = "修改文章")
    public JsonRequest<Integer> updateOneDocument(
            @Parameter(description = "文章", required = true)
            @RequestBody Document document) {
        return baseService.updateOneDocument(document);
    }

    /**
     * 删除文章
     *
     * @param id 文章id
     * @return JSON
     */
    @DeleteMapping
    @Operation(summary = "删除文章")
    public JsonRequest<Integer> deleteDocument(
            @Parameter(description = "文章id", required = true)
            @RequestBody List<Long> id) {
        return baseService.deleteDocument(id);
    }
}




